{template 'weheader'}
{if $reside}<script src="{MODULE_URL}template/weui/js/city-picker.min.js"></script>{/if}
{if $isloc}<script type="text/javascript" src="{TEMPLATE_WEUI}js/QQgetLocation.js"></script>{/if}
<style>
body{background-color:#fbf9ff;}
.weui-header .weui-header-left,.weui-header .weui-header-right{top: 5px;}
.dayu-header {padding: 25px 0 0;}

.weui_cells {margin-top:10px;}
.fields{margin-top:10px;}
.fields .weui_cells{margin-top:2px;}

.weui_textarea_counter span {font-size:12px;}
.weui_label span{color: #E64340;}
.weui-popup-container{z-index:9999;}
.weui_cell_select .weui_cell_td {padding-left: 1em;}
.weui_cell_select .weui_cell_hd .weui_select {line-height:45px;padding:0 25px 0 5px;color: #555;}

.weui_msg .weui_extra_area {margin-bottom: 5px;}
.weui_extra_area {z-index:0;}
.record .weui_cells:first-child {margin-top:30px;}
.record .weui_cells {margin:0;}
.record img{width:1.2rem;height:1.2rem;}

.weui_uploader_files {width:60%;float:left; list-style: none;height:100px; background: no-repeat center center; background-size: 100px auto; margin-bottom: 2px;text-align:center;}
.dayu_uploader_input {float: left; position: relative; margin: 0px; margin-bottom: 0px; width: 40%; height: 100px;; border: 0px solid #D9D9D9;}
.dayu_uploader_input span{line-height:15px;margin-top:5px;color:#666;}
.dayu_uploader_input span:last-child{margin-top:0px;position: absolute;bottom:0;display:block;}

.weui_uploader_file {text-align:center;
  float: left;
  margin-right: 9px;
  margin-bottom: 9px;
  width: auto;
  height: 100px;
  background: no-repeat center center;
  background-size: 100px auto;
  padding:100px auto;}
.m-img {background-position: top center;padding-bottom: 0;}
.m-img img{width:100%;height:auto;}
.m-masker {background-color: rgba(0, 0, 0, 0);position: relative;}
</style>

	{template 'insert/header'}

	{if $activity['isinfo']}
		{template 'insert/field_address'}
	{/if}

<form action="{php echo $this->createMobileUrl('dayu_form', array('weid' => $_W['uniacid'], 'id' => $reid))}" class="" enctype="multipart/form-data" method="POST" id="form">
<input type="hidden" name="repeat" value="<?php echo md5(sha1(time())); ?>">

	{if $activity['paixu']==0}
		{template 'insert/join'}
	{/if}
	
	{if !empty($par['kami']) && pdo_tableexists('dayu_kami')}
		{template 'insert/field_kami'}
	{/if}
	
	{if !empty($linkage)}
		{template 'insert/field_linkage'}
	{/if}
	
	<div class="fields">
	
	{loop $ds $fields}
	
	{if $fields['type'] == 'text'}
		{template 'insert/field_text'}
	{/if}
		
	{if $fields['type'] == 'email'}
		{template 'insert/field_email'}
	{/if}
				
	{if $fields['type'] == 'number'}
		{template 'insert/field_number'}
	{/if}
				
	{if $fields['type'] == 'textarea'}
		{template 'insert/field_textarea'}
	{/if}
				
	{if $fields['type'] == 'radio'}
		{template 'insert/field_radio'}
	{/if}
				
	{if $fields['type'] == 'checkbox'}
		{template 'insert/field_checkbox'}
	{/if}
						
	{if $fields['type'] == 'select'}
		{template 'insert/field_select'}
	{/if}

	{if $fields['type'] == 'image'}
    <div class="weui_cells weui_cells_form">
        <div class="weui_cell">
            <div class="weui_cell_bd weui_cell_primary">
                <div class="weui_uploader">
                    <div class="weui_uploader_bd row">
                        <div class="weui_uploader_files col-60">   
                            <input type="hidden" name="field_{$fields['refid']}_{$fields['bind']}" accept="image/*" capture="camera" value="" {if $fields['essential']}required tips="{$fields['tixing']}"{/if}/>                        
                            <image class="middle" onclick="show(this,'show{$fields['refid']}')" id="show{$fields['refid']}" src="{php echo tomedia($fields['image'])}" style="height:100px;width:auto;" />
                        </div>
                        <div class="dayu_uploader_input col-40" data="field_{$fields['refid']}_{$fields['bind']}" onclick="upimg(this,{$fields['refid']})" id="{$fields['refid']}">
							{$fields['title']}{if $fields['essential']} <span class="f-red f18">*</span>{/if}
							<span class="f12 left">{php echo urldecode($fields['description'])}</span>
							<span class="weui_btn weui_btn_mini weui_btn_default left">上传图片</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	{/if}
				
	{if $fields['type'] == 'calendar'}
		{template 'insert/field_calendar'}
	{/if}
		
	{if $fields['type'] == 'range'}
		{template 'insert/field_range'}
	{/if}
		
	{if $fields['type'] == 'reside'}
		{template 'insert/field_reside'}
	{/if}
	
	{/loop}
	</div>
	
	{if $activity['plural']==1}
		{template 'insert/pics'}
	{/if}
	
	{if $activity['isvoice']==1}
		{template 'insert/voice'}
	{/if}
	
	{if $activity['paixu']==1}
		{template 'insert/join'}
	{/if}
	
    <div class="weui_btn_area row">
	{if !empty($activity['agreement'])}
		{template 'insert/field_agreement'}
	{/if}
		{template 'insert/field_var'}
		<input type="hidden" name="token" value="{$_W['token']}" />
        <button class="weui_btn weui_btn_primary" name="submit" type="submit" id="showTool">{$submitname}</button>
    </div>
</form>
	{template 'insert/field_footer'}
	{if !empty($par['comment']) && pdo_tableexists('dayu_comment')}
	</div>
        <div class="weui_tab_bd_item">
            {template 'insert/comment'}
        </div>
	{/if}
</div>
	{template 'insert/popup'}
	
<script type="text/javascript">
{if !empty($par['kami']) && pdo_tableexists('dayu_kami')}
	function checkcard(obj,id){
		var card = $("#kami").val();
		var divA = document.getElementById("ka");
		$.showLoading('查询中...');
		$.getJSON('{php echo murl('entry', array('do' => 'CheckCard','m' => 'dayu_kami'), true, true)}', {'op' : 'card', 'id' : id, 'reid' : '{$reid}', 'card' : card, 'title' : obj.getAttribute("data")}, function(s){
			if (s.message.status==0) {
				setTimeout(function() {
					$.hideLoading();
				}, 1000);				
				$.alert(s.message.msg, "提示");
				$("#kami").val("");
				divA.innerHTML = '<i class="weui_icon_warn"></i>';
			}else if(s.message.status==1){
				setTimeout(function() {
					$.hideLoading();
					divA.innerHTML = '<i class="weui_icon_success"></i>';
				}, 1000);
			}else{
				setTimeout(function() {
					$.hideLoading();
					$('#mi').html("");
				}, 1000);
				$.toast(s.message.msg);
			}
		});
	}
	function checkpass(obj,id){
		var card = $("#kami").val();
		var pass = $("#pass").val();
		var divA = document.getElementById("mi");
		$.getJSON('{php echo murl('entry', array('do' => 'CheckCard','m' => 'dayu_kami'), true, true)}', {'op' : 'pass', 'id' : id, 'reid' : '{$reid}', 'card' : card, 'pass' : pass, 'title' : obj.getAttribute("data")}, function(s){
			if (s.message.status==0) {
				setTimeout(function() {
					$.hideLoading();
				}, 1000);				
				$.alert(s.message.msg, "提示");
				$("#pass").val("");
				divA.innerHTML = '<i class="weui_icon_warn"></i>';
			}else if(s.message.status==1){
				setTimeout(function() {
					$.hideLoading();
					divA.innerHTML = '<i class="weui_icon_success"></i>';
				}, 1000);
			}else{
				setTimeout(function() {
					$.hideLoading();
					$('#mi').html("");
				}, 1000);
			}
		});
	}
{/if}
	function check(obj,refid){
		var content = $("#n_"+refid).val();
		$.getJSON('{php echo $this->createMobileUrl('checkonly')}', {'reid' : '{$reid}', 'refid' : refid, 'content' : content, 'title' : obj.getAttribute("data")}, function(s){
			if (s.message.status==0) {
				$.alert(s.message.msg, "提示");
				setTimeout(function() {
					$("#n_"+refid).val(""); 
				}, 2000)
			}
		});
	}
function upimg(obj,id){
	var images = {
		localId: [],
		serverId: []
	};
	wx.chooseImage({
		count: 1,
		sourceType: ['album', 'camera'],
		success:function(res){
		images.localId = res.localIds;
		var i = 0, length = images.localId.length;
		var wxUpload = function() {
			wx.uploadImage({
				localId: images.localId[i],
				isShowProgressTips: 1,
				success: function (res) {
					i++;
					images.serverId.push(res.serverId);
					var url = "{php echo $this->createMobileUrl('uploads',array('type'=>'image'));}&serverId=" + res.serverId + "&localId=" + i;
					$.post(url, function(dat){
						var dat = eval("("+dat+")");
							if (dat.status == 'success') {
								$.toast(dat.message, "success");
								$('input[name="'+obj.getAttribute("data")+'"]').val(tomedia(dat.path));
								document.getElementById('show'+id).src = tomedia(dat.path);
							}else{
								$.toast(dat.message, "cancel");
								document.getElementById('show'+id).src = "";
							}
					});
					if(i < length){
						wxUpload();
					}
				},
				fail: function (res) {
					alert(JSON.stringify(res));
				}
			});						
		};
		wxUpload();
		}
	});
}
function show(obj,id){
	var pic=document.getElementById(id).src;
	wx.previewImage({
		current: pic,
		urls: [pic]
		
	});
}
	function fetchgetjs(obj) {
		$('#linkage2').empty();
		$('#linkage2').append('<option value="">请选择</option>');
		if (!$(obj).val()) {
			return false;
		}

		$.getJSON('{php echo $this->createMobileUrl('GetLinkage')}', {'linkage1' : $(obj).val()}, function(s){
			if (s.message.status == 0) {
				$.toast(s.message.jss, 'cancel');
				return false;
			}
			$('#linkage2').empty();
			if (s.message.jss) {
				for (i in s.message.jss) {
					$('#linkage2').append('<option value="'+s.message.jss[i].id+'">'+s.message.jss[i].title+'</option>');
				}
			} 
		});
	}
	
var $form = $("#form");
$form.form();
$("#formSubmitBtn").on("click", function(){
	{if $activity['paixu']=='0' || $activity['paixu']=='1'}
		var member=$("#member").val();
		var reg = /^[\u4E00-\u9FA5]{1,6}$/;
		if (!reg.test(member)){
			$.alert( "请正确输入{$activity['member']}");
			return false ;
		}
		var mobile=$("#mobile").val();
		var mobilenumber = /^(((13[0-9]{1})|(14[7-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
		if(mobile=='' || !mobilenumber.test(mobile)){
			$.alert("请输入正确的{$activity['phone']}");
			return false;
		}
	{/if}
	{if $ycredit < "0"}
		$.toast("{$creditnames[$behavior['activity']]['title']}不足{$activity['credit']},不能提交", "cancel");
		return false;
	{/if}
	{if !empty($activity['agreement'])}
		if (document.getElementById("agreement").checked == false){
			$.alert("请仔细阅读并同意{$activity['agreement']}", "提示");
			document.getElementById("agreement").focus();
			return false;
		}
	{/if}
		
	{loop $ds $fields}
		{if $fields['essential']}
			{if in_array($fields['type'], array('text', 'calendar', 'email', 'range','image','textarea','number', 'radio', 'select'))}
				if($('input[name="field_{$fields['refid']}_{$fields['bind']}"]').val() == '' || $('textarea[name="field_{$fields['refid']}_{$fields['bind']}"]').val() == '') {
					$.toast("{$fields['title']} 不能为空", "cancel");
					return false;
				}
			{/if}
			{if in_array($fields['type'], array('checkbox'))}		
				if($(':checkbox[name="field_{$fields['refid']}_{$fields['bind']}[]"]:checked').length == 0) {
					$.alert("{$fields['title']} 必须选择", "提示");
					return false;
				}
			{/if}
			{if in_array($fields['type'], array('number'))}
				var num = parseFloat($("#field_{$fields['refid']}").val());
				if(isNaN(num)) {
					$.toast('{$fields['title']} 必须输入数字.');
					return false;
				}
			{/if}
			{if in_array($fields['type'], array('email'))}
				var mail = $('input[name="field_{$fields['refid']}_{$fields['bind']}"]').val();
				if(!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/i).test(mail)) {
					$.alert("{$fields['title']} 请正确邮箱地址", "提示");
					return false;
				}
			{/if}
		{/if}
	{/loop}
		
	{if $activity['isvoice']==1 && $activity['ivoice']==1}
		if($.trim($(':hidden[name="voice"]').val()) == '') {
			$.alert("请上传{$activity['voice']}", "提示");
			return false;
		}
	{/if}
	
	$form.validate(function(error){		
		if(error){
            
		}else{
			$.showLoading('正在提交...');
        }
    });
});
</script>
{template 'footers'}